﻿<UserControl x:Class="SPIWareMVVM.Views.WorkOrderList"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:conv="clr-namespace:SPIWareMVVM.Views.Conversions"
             xmlns:me="clr-namespace:SPIWareMVVM.ViewModels" 
             xmlns:views="clr-namespace:SPIWareMVVM.Views"
             xmlns:ctrl="clr-namespace:System.Windows.Controls;assembly=PresentationFramework"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ObjectDataProvider x:Key="workOrdersVM" ObjectType="{x:Type me:WorkOrdersViewModel}"/>
        <ObjectDataProvider x:Key="applicationData" ObjectType="{x:Type me:ApplicationData}"/>
        <conv:BoolToVisibilityConverter x:Key="boolToVis" />
    </UserControl.Resources>
    <DockPanel>
        <ToolBar DockPanel.Dock="Top">
            <TextBlock DockPanel.Dock="Top" Text="Work Orders" Background="Azure" Width="Auto"/>
            <Separator/>
            <Button x:Name="btnOpenClosed" Content="Displaying All" Click="btnOpenClosed_Clicked"/>
            <Separator/>
            <Button x:Name="btnPrint" Content="Print" Click="cmdPrintWO"/>
        </ToolBar>

        <ListBox DockPanel.Dock="Left" x:Name="lbWorkOrders" ItemsSource="{Binding Path=WorkOrderList, Source={StaticResource applicationData}, Mode=TwoWay}"
                 SelectionChanged="WorkOrders_SelectionChanged"/>
        <DockPanel x:Name="dpWorkOrderEdit" DockPanel.Dock="Top" Visibility="Collapsed" IsEnabled="{Binding SelectedItem.IsEditable, ElementName=lbWorkOrders}">
            <StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
                <TextBlock Text="("/>
                <TextBlock Text="{Binding Path=SelectedItem.WorkOrderId, ElementName=lbWorkOrders}"/>
                <TextBlock Text=") "/>
                <TextBlock Text="{Binding Path=SelectedItem.Quantity, ElementName=lbWorkOrders}"/>
                <TextBlock Text=" "/>
                <TextBlock Text="{Binding Path=SelectedItem.Part.Description, ElementName=lbWorkOrders}"/>
                <TextBlock Text=" "/>
                <TextBlock Text="{Binding Path=SelectedItem.Status, ElementName=lbWorkOrders}"/>
            </StackPanel>
            <ToolBar DockPanel.Dock="Left" Background="MidnightBlue"/>
            <Grid DockPanel.Dock="Top">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="85"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <TextBlock Grid.Column="0" Grid.Row="1" Text="Customer / PO: "/>
                <TextBlock Grid.Column="0" Grid.Row="2" Text="Part: "/>
                <TextBlock Grid.Column="0" Grid.Row="3" Text="QTY: "/>
                <TextBlock Grid.Column="0" Grid.Row="5" Text="Received On: "/>
                <TextBlock Grid.Column="0" Grid.Row="6" Text="Due By: "/>

                <StackPanel x:Name="spCustomerInformation" Orientation="Vertical" Grid.Column="1" Grid.Row="1" >
                    <StackPanel Orientation="Horizontal">
                        <!--SelectionChanged="Part_SelectionChanged" -->
                        <ComboBox x:Name="cboCustomers" SelectionChanged="cboCustomers_SelectionChanged"
                              DisplayMemberPath="{Binding Path=Name}"
                              SelectedValuePath="{Binding Path=CustomerId}"
                              SelectedValue="{Binding Path=SelectedItem.CustomerId}"
                              ItemsSource="{Binding Path=ocCustomers, Source={StaticResource applicationData}}"/>
                        <TextBox Text="{Binding Path=SelectedItem.Customer.Name, ElementName=lbWorkOrders}"/>
                    </StackPanel>
                    <TextBox Text="{Binding Path=SelectedItem.CustomerPO, ElementName=lbWorkOrders}"/>
                </StackPanel>
                <StackPanel x:Name="spPart" Grid.Column="1" Grid.Row="2" Orientation="Vertical">
                    <TextBlock Text="{Binding Path=SelectedItem.Part.Description, ElementName=lbWorkOrders}"/>
                    <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="2">
                        <ComboBox x:Name="cboParts" SelectionChanged="Part_SelectionChanged"
                              DisplayMemberPath="{Binding Path=Description}"
                              SelectedValuePath="{Binding Path=PartId}"
                              SelectedValue="{Binding Path=SelectedItem.PartId}"
                              ItemsSource="{Binding Path=SelectedItem.CustomerParts.Part, ElementName=lbWorkOrders}"/>
                        <Button Command="{Binding Path=ViewAllPartsCommand, Source={StaticResource workOrdersVM}}"
                        CommandParameter="{Binding ElementName=cboParts}">
                            <Image Source="..\Images\ViewAll.png" Height="24" Width="24"/>
                        </Button>
                    </StackPanel>
                </StackPanel>
                <StackPanel x:Name="spQuantity" Grid.Column="1" Grid.Row="3" Orientation="Horizontal">
                    <TextBox Text="{Binding Path=SelectedItem.oQuantity, ElementName=lbWorkOrders}"/>
                    <TextBlock Text=" originally "/>
                    <TextBlock Text="{Binding Path=SelectedItem.QuantityOrdered, ElementName=lbWorkOrders}"/>
                    <TextBlock Text=" Corrected To "/>
                    <TextBlock Text="{Binding Path=SelectedItem.CorrectedQuantity, ElementName=lbWorkOrders}"/>
                </StackPanel>
                <TextBlock Grid.Column="1" Grid.Row="5" Text="{Binding Path=SelectedItem.DateReceived, ElementName=lbWorkOrders}"/>
                <ctrl:DatePicker Grid.Column="1" Grid.Row="6" SelectedDate="{Binding Path=SelectedItem.DateDue, ElementName=lbWorkOrders}"/>
            </Grid>
            <views:MaterialEdit x:Name="materialEdit"/>
            <!--<TextBlock Text="Materials Needed" VerticalAlignment="Center" FontStyle="Italic" Margin="4" FontSize="12"/>
            <TextBlock Text="Scheduling" VerticalAlignment="Center" FontStyle="Italic" Margin="4" FontSize="12"/>-->
        </DockPanel>
    </DockPanel>
</UserControl>
